script_enemy_main{

let phase=0;

let character="Midori";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=27;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshotb6=("script\SoundEffects\shotb6.wav");

let BG1=("\script\Images\BackgroundLayers\Midori3.png");
let GRboss=("\script\Images\CharacterSprites\Midori.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsMidori1.txt");

	LoadSE("script\SoundEffects\shotb6.wav");

	LoadGraphic("\script\Images\BackgroundLayers\Midori3.png");
	LoadGraphic("\script\Images\CharacterSprites\Midori.png");

	SetScore(250000);
	SetLife(300);
	SetTimer(40);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);
	
	SetCommonData("NoItem",0);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(32,32,32,32);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=5; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Arachnophobia [Fear of Spiders] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);

if(time%200==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+60,miny+120),1.5);
	}
}

if(frame==60){
let size=20;
let shot1=0;
let angle1=10;
let speed1=2;
let shot2=1;
let shot3=2;
let shot4=3;
let delay2time=20;
let color=11;
if((phase+0)%2==0){ color=59; }
if((phase+1)%2==0){ color=51; }
	loop(size){
	CreateShotA(shot1,GetX,GetY,0);
	SetShotDataA(shot1,0,speed1,angle1,0,0,0,color);

	let delay2=24;
	let speed3=0.23;
		loop(40){
		CreateShotA(shot2,0,0,0);
		SetShotDataA(shot2,0,0,0,0,0,0,color);
		SetShotDataA(shot2,150,0,GetAngleToPlayer+rand(-3,3),0,rand(0.005,0.01),1.2,color);

		if(delay2%24==0){
			CreateShotA(shot3,0,0,0);
			if((phase+0)%2==0){ SetShotDataA(shot3,0,speed3,angle1+90+(360/(size*2)),0,0,0,color); }
			if((phase+1)%2==0){ SetShotDataA(shot3,0,speed3,angle1-90-(360/(size*2)),0,0,0,color); }
			SetShotDataA(shot3,150,0,GetAngleToPlayer+rand(-3,3),0,rand(0.005,0.01),1.2,color);
			SetShotKillTime(shot3,60);

			let delay4=60/3;
				loop(2){
				CreateShotA(shot4,0,0,0);
				SetShotDataA(shot4,0,0,0,0,0,0,color);
				SetShotDataA(shot4,150,0,GetAngleToPlayer+rand(-3,3),0,rand(0.005,0.01),1.2,color);
				AddShot(delay4,shot3,shot4,0);
				delay4+=60/3;
				}
			AddShot(0,shot2,shot3,0);
			speed3+=0.24;
		}
		AddShot(delay2,shot1,shot2,0);
		delay2+=12;
		}
	FireShot(shot1);
	angle1+=360/size;
	}

let angle=GetAngleToPlayer+rand(-12,12);
	loop(18){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Midori - Fear of Spiders - Familiar.txt",GetX,GetY,rand(1.5,2),angle+rand(-5,5),0);
	angle+=360/18;
	}
PlaySE(SEshotb6);
}

if(frame>60 && GetEnemyShotCount==0){ phase+=1; frame=0; }
if(frame==400){ phase+=1; frame=0; }

if(OnPlayerMissed==true){ frame=0; }


if(GetTimer<1 || GetLife<=0){ SetCommonData("NoItem",1); }

if(GetCommonDataDefault("FamiliarDestroyed",0)==1 && OnBomb==false){ AddLife(-25); SetCommonData("FamiliarDestroyed",0); }
if(GetCommonDataDefault("FamiliarDestroyed",0)==1 && OnBomb==true){ SetCommonData("FamiliarDestroyed",0); }

time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<255){ bgfade+=5; }

	SetGraphicRect(0,0,300,300);
	SetGraphicScale(2,2);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,time/8);
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}